﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
namespace BanXeHoi.DataAccessLayer
{
    public class DAL
    {
        SqlConnection sqlCon;
        public DAL(string str)
        {
            sqlCon = new SqlConnection(str);
        }

        public DataTable GetData(string query)
        {
            DataTable dt = new DataTable();
            if (sqlCon.State != ConnectionState.Open)
            {
                sqlCon.Open();
            }
            SqlDataAdapter adapter = new SqlDataAdapter(query, this.sqlCon);
            adapter.Fill(dt);
            return dt;
        }

        public void OperateData(string query)
        {
            if (sqlCon.State != ConnectionState.Open)
            {
                sqlCon.Open();
            }
            SqlCommand cmd = new SqlCommand(query, sqlCon);
            cmd.ExecuteNonQuery();
            cmd.Dispose();
        }
    }
}